# Contributor: Leo <thinkabit.ukim@gmail.com>
# Maintainer:
pkgname=startup
pkgver=2.0.3
pkgrel=4
pkgdesc="Event driven task and service manager"
options="!check"
url="https://gitlab.com/chinstrap/startup"
arch="all"
license="GPL-2.0-only"
makedepends="
	autoconf
	automake
	libtool
	gettext-dev
	libnih-dev
	eudev-dev
	dbus-dev
	json-c-dev
	cgmanager-dev
	linux-headers
	glib-dev
	dconf-dev
	"
checkdepends="python3 dbus"
# https://gitlab.com/chinstrap/startup/issues/42
checkdepends="$checkdepends coreutils"
subpackages="
	$pkgname-dev
	$pkgname-doc
	$pkgname-lang
	$pkgname-tools::noarch
	libupstart:libs
	$pkgname-bridge-udev
	$pkgname-bridge-dconf
	$pkgname-fish-completion
	"
source="$pkgname-$pkgver.tar.gz::https://gitlab.com/chinstrap/startup/-/archive/$pkgver/startup-$pkgver.tar.gz"

prepare() {
	default_prepare
	autoreconf -fi
}

build() {
	export LDFLAGS="$LDFLAGS -lintl"
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--sysconfdir=/etc \
		--prefix=/usr \
		--disable-sysvcompat \
		--disable-static
	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install
	rm -rf "$pkgdir"/usr/lib/*.la

	# Install fish completion
	install -Dm0644 contrib/fish_completion/*.fish \
		-t "$pkgdir"/usr/share/fish/vendor_completions.d
	
	mkdir -p "$pkgdir"/usr/share/dbus-1/system.d/
	mv "$pkgdir"/etc/dbus-1/system.d/* "$pkgdir"/usr/share/dbus-1/system.d/
}

tools() {
	depends="$pkgname=$pkgver-r$pkgrel py3-dbus py3-gobject3"
	pkgdesc="Monitoring and analysis tools for Startup"

	amove usr/bin/initctl2dot
	amove usr/bin/startup-monitor
	amove usr/share/icons
	amove usr/share/applications
}

dconf() {
	pkgdesc="Dconf event bridge for Startup"
	install_if="$pkgname=$pkgver-r$pkgrel dconf"

	amove usr/libexec/startup/bridge/dconf
	amove usr/share/xdg/startup/bridge-dconf.conf
	amove usr/share/xdg/startup/bridge-dconf.override
}

udev() {
	pkgdesc="Udev event bridge for Startup"
	install_if="$pkgname=$pkgver-r$pkgrel eudev"

	amove usr/libexec/startup/bridge/udev
	amove usr/share/startup/bridge-udev.conf
	amove usr/share/startup/bridge-udev.override
	amove usr/share/xdg/startup/bridge-udev.conf
	amove usr/share/xdg/startup/bridge-udev.override
}

sha512sums="
02c504fa7f702c709cfe8fca7e413aff38374b0dc1eba52ba40dae6990ca4db3dcd2561de2713e0153ed47a75db8caaef628d92298049b39f83c6da97ef01e3a  startup-2.0.3.tar.gz
"
